# -*-encoding:utf8-*-
from include.GService import GService
from include.tools import *
from pymysql.pymysql import DB


class passport(GService):
    @classmethod
    def login(cls, phone=None, password=None):
        """

        :param phone:
        :param password:
        :return:
        """
        if phone == '' or password == '':
            return cls.SFAIL('账号密码不能为空')

        # 查询数据库
        res = DB("fuwu").Select("password").From("user_info").Where("phone=?", [phone]).GetRow()
        if len(res) == 0:
            return cls.SFAIL('用户不存在')
        res_password = md5(str(md5(phone) + str(res.get("password"))))
        if res_password != password:
            return cls.SFAIL('账号或密码错误')

        return cls.SOK()

